﻿fs.util.allowpoint = true;


$(document).on('keypress', '.commontable input.ms-input', function (event) {
    if (fs.util.allowpoint) {
        if (event.keyCode == 46 && this.value.indexOf(".") != -1) return false
        if (event.keyCode == 45 && this.value.indexOf("-") != -1) return false;
        return (event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode == 45) || (event.keyCode == 46)
    } else {
        if (event.keyCode == 45 && this.value.indexOf("-") != -1) return false;
        return (event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode == 45)
    }
}).on('change', '.commontable input.ms-input', function (event) {
    this.value = this.value.commafy();
})
.on('focus', '.commontable input.ms-input', function () {
    if (this.value == 0) {
        this.value = "";
    }
}).on('blur', '.commontable input.ms-input', function () {
    if (!this.value.trim()) {
        this.value = "0";
    }
})

var refrenceData = {
    table: [],
    loadingFile: {},
    get: function (title, fieldtype, field, process, index) {

        var list = this.table.filter(function (obj) { return obj.title == title; });
        var listdata = {};
        var newlist = title.indexOf('Budget_') != -1 || title.indexOf('Forecast_') != -1 || title.indexOf('Actual_') != -1 || title.indexOf('Common_') != -1;
        var _fieldInstance = createFieldTypeInstance(field, fieldtype);
        fieldtype = _fieldInstance.type;
        field = _fieldInstance._field;

        var isloadingFile = title.toUpperCase().indexOf("LOADINGFILE") != -1;

        var opt = {
            Month: fs.form.month,
            Year: fs.form.year,
            ListTitle: title,
            Data: "",
            CompanyCode: fs.form.companycode
        };

        opt.withmonth = title.indexOf('Forecast_') != -1 || title.indexOf('Actual_') != -1 || title.indexOf('Common_') != -1;

        if (process.lastyear) {
            opt.Year -= 1;
        }
        else if (process.lastDec) {
            opt.Year -= 1;
            opt.Month = 12;
        }
        if (process.lastmonth) {
            if (opt.Month == 1) {
                opt.Month = 12;
                opt.Year -= 1;
            } else
                opt.Month -= 1;
        }
        if (process.passtwoyear) {
            opt.Year -= 2;
            opt.Month = 12;
        }
        if (process.month) {
            opt.Month = process.month;
        }

        if (process.passMonth) {
            if (!window.AllCurrentYearItemsCompressObject)
                window.AllCurrentYearItemsCompressObject = getPassMonthCompressObject();
            var row = AllCurrentYearItemsCompressObject.filter(function (obj) { return obj.accountcode == field })[0];
            if (row) {
                var itemValue = fs.util.strFilter(row[fieldtype]);
                return parseFloat(itemValue);
            }
            return 0;
        }
        if (isloadingFile) {
            opt.ActionType = "LoadingFile";
            if (process.query) {
                opt.RGCCategory = process.query;
            }
            return this.loadingFileAdapter(opt, title, fieldtype, field, index, process);
        }

        if (newlist)
            return this.newAdapter(opt, title, fieldtype, field);
        else
            return this.oldAdapter(opt, title, fieldtype, field);
    },
    oldConnector: function (opt) {
        var item = {
            title: opt.title, year: 0, month: 0, companycode: '', fields: {}
        };

        this.receive(opt
        , function (d) {
            item.year = d.Year;
            item.month = d.Month;
            item.companycode = d.CompanyCode;
            if (d.Data && d.Data.Data)
                item.fields = JSON.parse(d.Data.Data);
            else {
                fs.util.log(JSON.stringify(d) + "--Data can not found!");
                item.fields = {};
            }
        });

        this.table.push(item);
        return item;
    },
    oldAdapter: function (opt, title, fieldtype, field) {
        var list = this.table.filter(function (obj) {
            return obj.title == opt.ListTitle
                    && obj.month == opt.Month && obj.year == opt.Year && obj.companycode == opt.CompanyCode;
        });
        var listdata = {};

        if (list.length == 0)
            listdata = this.oldConnector(opt);
        else
            listdata = list[0];

        var fieldtype = '', fieldname = '';

        if (field.indexOf("_") == -1 && !field.startWith('HR') && fs.util.autoAppendProfixToReceive && !field.startWith('SV'))
            field = "CM_" + field;

        var value = fs.form.receiveSpecialFieldValue({ obj: listdata.fields, field: field }, '_', true);
        return parseFloat(value) ? parseFloat(value) : 0.00;
    },
    loadingFileAdapter: function (opt, title, fieldtype, field, index, process) {
        var value = 0;

        this.receive(opt
        , function (d) {

            if (d.Success && d.Data) {
                var items = d.Data;
                var row = items.filter(function (r) { return r.Period == index });
                if (row.length > 0) {
                    var item = row[0];
                    var itemValue = fs.util.ref(item, field);
                    itemValue = fs.util.strFilter(itemValue);
                    if (!itemValue)
                        fs.util.log(" [loadingfile context]" + field + "---" + fieldtype + " field is now found !");
                    else {
                        value = parseFloat(itemValue);
                    }
                }
            }
            else {
                fs.util.log(" [loadingfile context]" + JSON.stringify(d) + " -- Data can not found!");
            }
        });

        return value;
    },
    newAdapter: function (opt, title, fieldtype, field, sub) {
        var value = 0;

        opt.pars = String.format(" (Year eq {0}) and (CompanyCode eq '{1}')", opt.Year, fs.form.companycode);
        if (opt.withmonth) {
            opt.pars = String.format(" (Month eq {0}) and (Year eq {1}) and (CompanyCode eq '{2}')", opt.Month, opt.Year, fs.form.companycode);

            if (!opt.CompanyCode)
                opt.pars = String.format(" (Month eq {0}) and (Year eq {1})", opt.Month, opt.Year);
        }
        else if (!opt.CompanyCode) {
            opt.pars = String.format(" (Year eq {0})", opt.Year);
        }

        fs.form.receiveGrayFieldValue({
            title: opt.ListTitle,
            month: opt.Month,
            year: opt.Year,
            pars: opt.pars
        }, false, function (d) {

            if (d.d.results.length > 0) {
                var billData = JSON.parse(d.d.results[0].BillData);
                if (billData != null) {
                    var row = billData.filter(function (obj) { return obj.accountcode == field })[0];
                    if (!row)
                        fs.util.log(field + " field is now found ! [refrence context]");
                    else {
                        if (fieldtype == "BudgetYTDM") {
                            value = fs.util.getBudgetItemYTDMValue(row, opt.Month);
                        } else {
                            var itemValue = fs.util.strFilter(row[fieldtype]);
                            value = parseFloat(itemValue);
                        }

                        if (sub && sub.subrow) {
                            value = 0;
                            var subrow = row.subrow.filter(function (obj) { return obj.entity == sub.identity });
                            if (subrow.length > 0) {
                                subrow = subrow[0];
                                value = parseFloat(subrow[fieldtype]);
                            }
                        }

                    }
                }
            }
        });

        return value;
    },
    receive: function (se, callback, addition, noCache) {

        if (!se.CompanyCode) return 0.00;
        se.ActionType = se.ActionType ? se.ActionType : "Utility";
        se.SiteUrl = fs.sys.siteUrl;
        if (!addition)
            addition = "";

        var cacheIdentity = JSON.stringify(se);

        for (var i = 0; i < fs.util.cache.length; i++) {
            var cacheItem = fs.util.cache[i];
            if (cacheItem.identity == cacheIdentity) {
                callback(cacheItem.data);
                return;
                break;
            }
        }

        $.ajax({
            url: fs.sys.siteUrl + '/_layouts/ajaxservices/servicelocator.ashx',
            data: "se=" + encodeURIComponent(JSON.stringify(se)) + addition + "&timemark=" + new Date().getTime(),
            async: false,
            error: function (e) {
                fs.util.log(e);
                fs.ui.clear("#s4-workspace");
            },
            success: function (data) {
                //   if (data.Success) {
                var cacheItem = {
                    source: se.ListTitle,
                    identity: cacheIdentity,
                    companycode: se.CompanyCode,
                    year: se.Year,
                    month: se.Month,
                    data: data
                };
                // if (d.d.results.length > 0)
                if (!noCache)
                    fs.util.cache.push(cacheItem);

                callback(data);
                //  }
            }
        })
    },
    post: function (se, callback, addition) {
        se.ActionType = se.ActionType ? se.ActionType : "ExcelServeice";
        fs.sys.siteurl = _spPageContextInfo.webServerRelativeUrl;
        $.ajax({
            type: "POST",
            url: fs.sys.siteUrl + '/_layouts/ajaxservices/servicelocator.ashx',
            data: { se: encodeURIComponent(JSON.stringify(se)) },
            //  contentType: "application/json; charset=utf-8",
            error: function (error) {
                fs.util.log(e);
            },
            success: function (data) {
                callback(data);
            }
        })
    }
}

var getPassMonthCompressObject = function () {
    var ytdQuery = String.format(" (Month lt {0}) and (Year eq {1}) and (CompanyCode eq '{2}')", fs.form.month, fs.form.year, fs.form.companycode);
    if (!fs.form.companycode) {
        ytdQuery = String.format(" (Month lt {0}) and (Year eq {1}) ", fs.form.month, fs.form.year);
    }

    var fs_AllCurrentYearItemsCompressObject = [];
    fs.form.receiveGrayFieldValue({
        title: fs.form.title,
        pars: ytdQuery
    }, false, function (d) {
        if (d.d.results.length > 0) {

            var itemTemplate = JSON.parse(d.d.results[0].BillData);

            for (var i = 1; i < d.d.results.length; i++) {
                var currentItem = JSON.parse(d.d.results[i].BillData);

                var index = 0;
                itemTemplate.forEach(function (itemRow) {

                    for (var field in itemRow) {
                        var fieldValue = fs.util.strFilter(itemRow[field]);
                        fieldValue = fieldValue == null ? 0 : fieldValue;
                        var cfieldValue = fs.util.strFilter(currentItem[index][field]);

                        if ((parseFloat(fieldValue) || parseFloat(fieldValue) == 0) && (parseFloat(cfieldValue) || parseFloat(cfieldValue) == 0)) {
                            fieldValue = parseFloat(fieldValue);
                            cfieldValue = parseFloat(cfieldValue);
                            itemRow[field] = fieldValue + cfieldValue;
                        }
                    }

                    index++;
                });

            }

            fs_AllCurrentYearItemsCompressObject = itemTemplate;
        }
    });

    return fs_AllCurrentYearItemsCompressObject;
}
var createFieldTypeInstance = function (fieldToFix, fieldtype) {
    var _res = {};

    if (fieldToFix.indexOf('|') == -1) {
        _res = { type: fieldtype, _field: fieldToFix }; ;
    } else {
        var splitField = fieldToFix.split('|');
        _res = { type: splitField[0], _field: splitField[1] };
        if (_res.type == "LM" && fs.form.isBudget()) {  //取上月值
            _res.type = getLastMonthRowText(fieldtype)
        }
    }
    return _res;
}

//Refrence&Budget_BS&BS03020300", "Refrence&Budget_BS&Dec|BS03020300
var searchFieldFunctionAdpter = function (field, exp, fieldtype) {
    field = field.replace(/&amp;/g, "&");
    var splitStr = field.split("&");
    var beforeReceiveField = splitStr[2], af = exp.equ;
    window.sffValue = 0
    window._sffValue = 0;

    //处理获取其它字段的情况
    var fixFieldType = function (fieldToFix) {
        var _res = createFieldTypeInstance(fieldToFix, fieldtype);

        if (splitStr.length > 3) {
            _res.type += splitStr[3];
        }
        if (_res.type.toUpperCase() == 'MOVEMENT') {
            movement(fieldtype, _res);
        }
        return _res;
    }
    var movement = function (f, res) {
        var c = viewModel.columns.filter(function (t) { return t.rowText == f; });
        if (c.length > 0) {
            c = c[0];
            af = '-';
            beforeReceiveField = c.rowText + ',' + c.lastMonthField;
            //  res.type = beforeReceiveField;
        }
    }
    //处理如果需要取MOVEMENT字段的情况 自动生成上月字段到beforeReceiveField中 如'Dec,Nov'
    var fieldPar = fixFieldType(beforeReceiveField);


    if (beforeReceiveField.indexOf(',') != -1) {
        var brf = beforeReceiveField.split(',');
        for (var i = 0; i < brf.length; i++) {
            var fieldToFix = brf[i];
            if (fieldToFix.indexOf('|') != -1)
                fieldPar = fixFieldType(fieldToFix);
            else
                fieldPar.type = fieldToFix;

            _sffValue = parseFloat(refrenceData.get(splitStr[1], fieldPar.type, fieldPar._field, exp));
            if (!isNaN(_sffValue))
                fs.util.eval('sffValue ' + af + '= _sffValue');
        }
    } else {
        sffValue = refrenceData.get(splitStr[1], fieldPar.type, fieldPar._field, exp);
    }

    return sffValue;
}

function getSubrowValueByIdentity(identity, fieldtype, model, digits) {
    var value = 0;
    if (!model)
        model = viewModel.items();

    model.forEach(function (obj) {
        if (obj.accountcode == identity) {
            value = parseFloat(unWarpValue(obj[fieldtype]));
            return value;
        }

        if (obj.subrow)
            unWarpValue(obj.subrow).forEach(function (row) {
                if (row.accountcode == identity) {
                    value = parseFloat(unWarpValue(row[fieldtype]));
                    //  fs.util.log('break!--' + value);
                    return value;
                }
            })
    });
    return fs.util.toFix(value, digits);
}

var searchData = {
    fields: [],
    put: function (identity, fieldtype, exp, index) {
        this.fields.push({ identity: identity, fieldtype: fieldtype, exp: exp, index: index });
    },
    cure: function (metadata) {
        this.fields.sort(by('index')).forEach(function (value) {

            // fs.util.log(value.identity + "-[Search Context]-" + JSON.stringify(value));
            if (value.exp.currentrow) {
                currentrowExp(metadata, value);
            }
            else if (value.exp.mode == 'search') {
                var row = metadata.items().filter(function (obj) { return obj.description == value.identity.description && obj.accountcode == value.identity.accountcode })[0];

                row[value.fieldtype] = ko.computed(function () {
                    var total = 0, exp = "", equ = "", index = 0, fieldtype = '';

                    if (value.exp.equexpression)
                        equ = value.exp.equ;
                    //  fs.util.log("[Search Context]" + JSON.stringify(value));

                    value.exp.fields.forEach(function (field) {
                        //支持从Process中定义FieldType
                        fieldtype = value.exp.fieldtype ? value.exp.fieldtype : value.fieldtype;

                        var v = 0;
                        if (field.startWith("Refrence")) {
                            v = searchFieldFunctionAdpter(field, value.exp, fieldtype);
                        }
                        else {

                            var _fieldObj = createFieldTypeInstance(field, fieldtype);
                            var refrenceRow = metadata.items().filter(function (obj) { return obj.accountcode == _fieldObj._field })[0];
                            if (!refrenceRow)
                                fs.util.log(field + " field is now found ! ");
                            else
                                v = parseFloat(unWarpValue(refrenceRow[_fieldObj.type]));
                        }

                        if (typeof v != 'undefined' && v + "" != "") {
                            if ($.isArray(value.exp.equ))
                                equ += "(" + v + ")" + value.exp.equ[index];
                            else if (value.exp.equexpression) {
                                var indexExpressiness = '\\{' + index + '\\}';
                                equ = equ.replace(new RegExp(indexExpressiness, 'g'), v);
                            }
                            else
                                equ += "(" + v + ")" + value.exp.equ;
                        }
                        index++;
                    })
                    // if ($.isArray(value.exp.equ))
                    if (!value.exp.equexpression)
                        equ = equ.substring(0, equ.length - 1);

                    total = fs.util.eval(equ);
                    if (value.exp.addition) {
                        total = fs.util.eval(String.format(value.exp.addition, total));
                    }

                    if (document.controlCalcEqual && value.identity.accountcode.trim().toUpperCase() == "CONTROL" && total != 0 && value.fieldtype != "L_Dec") {
                        document.controlCalcEqual = false;
                    }
                    if (!isNaN(total))
                        return total.toFix(row.digits);

                    return 0;
                })


                row.rowAfterBinding && row.rowAfterBinding(row);

            }
            else if (value.exp.mode == 'to') {

                var row = metadata.items().filter(function (obj) { return obj.description == value.identity.description && obj.accountcode == value.identity.accountcode })[0];
                var start = value.exp.start;
                var stop = value.exp.end;
                var equ = value.exp.equ;
                var fieldtype = value.fieldtype;

                row[value.fieldtype] = ko.computed(function () {
                    //   fs.util.log("[To Context]" + JSON.stringify(value));
                    var action = false;
                    var total = 0;
                    ko.utils.arrayForEach(metadata.items(), function (obj) {
                        if (obj.accountcode == start)
                            action = true;

                        if (action) {
                            var v = parseFloat(unWarpValue(obj[fieldtype]));
                            if (!isNaN(v)) {
                                eval(String.format("total{0}={1}", equ, v));
                            }
                        }
                        if (obj.accountcode == stop)
                            action = false;

                    });
                    if (value.exp.addition) {
                        total = fs.util.eval(String.format(value.exp.addition, total));
                    }
                    return total.toFix(row.digits);
                });
            }
        });
    }
}

var clearUp = function (obj) {
    for (var item in obj) {
        if (item.toLowerCase().indexOf("value") == -1 && item.toLowerCase().indexOf("items") == -1) {
            obj[item] = "";
        }
    }
    return obj;
}

var getDataFromLastYear = function (accountcode, month) {
    month = month ? month : 12;
    var rowValue = 0;

    var pars = String.format(" (Year eq {0}) and (CompanyCode eq '{1}')", fs.form.year - 1, fs.form.companycode);

    fs.form.receiveGrayFieldValue({
        title: fs.form.title,
        pars: pars
    }, false, function (d) {
        if (d.d.results.length > 0) {
            var jsonData = JSON.parse(d.d.results[0].BillData);
            if (jsonData != null) {
                var row = jsonData.filter(function (obj) { return obj.accountcode == accountcode })[0];
                rowValue = fs.util.ref(row, "Dec");
            }
        }
    });
    return rowValue;
}

var getValueFromLastTwoYears = function (list, accountcode, newAdapter, sub) {

    if (!newAdapter)
        return refrenceData.oldAdapter({ Year: fs.form.year - 2, Month: 12, CompanyCode: fs.form.companycode, Data: "", ListTitle: list }, list, "CM", accountcode)
    else
        return refrenceData.newAdapter({ withmonth: true, Year: fs.form.year - 2, Month: 12, CompanyCode: fs.form.companycode, Data: "", ListTitle: list }, list, "CM", accountcode, sub)

}

var getLastMonthData = function () {
    var jsonData = null;

    var lastMonth = fs.form.month - 1;

    fs.form.receiveGrayFieldValue({
        title: fs.form.title,
        month: lastMonth
    }, false, function (d) {
        if (d.d.results.length > 0) {
            jsonData = JSON.parse(d.d.results[0].BillData);
            if (jsonData != null)
                jsonData.forEach(function (obj) {
                    obj.dataFromLastMonth = true;
                    if (obj.withsubrow) {
                        obj.subrow.forEach(function (subrow) {
                            //  clearUp(subrow);
                            if (subrow.marketItems)
                                subrow.marketItems.forEach(function (market) {
                                    //market.Actual_M_2 = 0.00; //todo 从Refrence中获取数据 获取方式需要确认, 哪几个字段对应
                                    //market.Actual_M_1 = 0.00;
                                    market.FCST_M = market.FCST_M_1;

                                    market.FCST_M_1 = 0.00;
                                    market.FCST_M_2 = 0.00;
                                    market.FCST_M_3 = 0.00;
                                });
                        })
                    }
                });
        }
    });
    return jsonData;
}

var fs_unitMerger = function (unit) {
    var currency = fs.form.entitycurrency;
    if (currency.toUpperCase().startWith("K")) {
        currency = currency.substr(1);
    }
    unit = unit.replace("#T#", fs.form.entitytonnage);
    return String.format(unit, currency);
}

function unWarpValue(value) {
    var tempValue = ko.unwrap(value);

    if (tempValue != null && typeof tempValue != "undefined")
        return parseFloat(tempValue.toString().replace(/,/g, ""));
    return tempValue ? tempValue : 0;
}

function getLastMonthFieldData(identity, type, digits) {
    //    if (!window.fs_AllCurrentYearItemsCompressObject) {
    //        getRealYTDValue();
    //    }
    //    return getSubrowValueByIdentity(identity, "CM", window.fs_AllCurrentYearItemsCompressObject);

    if (!window.dataFromLastMonth) {
        window.dataFromLastMonth = getLastMonthData();
    }

    return getSubrowValueByIdentity(identity, type, window.dataFromLastMonth, digits);
}

function getLastMonthRowText(col) {

    var column = "", columnIndex = 0;
    if (typeof col == "string") {
        column = viewModel.firstColumns.filter(function (c) { return c.rowText == col })[0];
    } else
        column = col;

    return column.lastMonthField;

    var lastRowIndex = viewModel.firstColumns.length - 1;

    columnIndex = column.index - 2;
    columnIndex = columnIndex < 0 ? lastRowIndex : columnIndex;

    return viewModel.firstColumns[columnIndex].rowText;

    //    var column = viewModel.firstColumns.filter(function (c) { return c.index == col.index - 1 });
    //    if (column.length > 0) {
    //        return column[0];
    //    }
    //    return col;
}

function simpleConnector(currentModel, columnObj, expression, dataFromLastMonth) {
    if (columnObj.lastyear) {
        currentModel[columnObj.rowText] = getDataFromLastYear(expression.accountcode);
    }
    else if (dataFromLastMonth) {
        currentModel[columnObj.rowText] = ko.computed(function () {
            return unWarpValue(currentModel[getLastMonthRowText(columnObj)])
        });
    }
    else if (fs.form.mode != "New" || fs.form.merge) {
        currentModel[columnObj.rowText] = ko.observable(fs.util.getNumberFromObjectAndFix(expression, columnObj.rowText, 0, expression.digits));  //Chcange 2014-06-07   2014-12-28
        currentModel[columnObj.rowText + "style"] = 'none';
    } else {
        currentModel[columnObj.rowText] = ko.observable(0);  //Chcange 2014-0902
        currentModel[columnObj.rowText + "style"] = 'none';
    }
}
function expressionConnector(currentModel, columnObj, expression) {

    var process = expression.Process.filter(function (obj) { return columnObj.rowText.trim() == obj.Field.trim(); });

    if (process.length == 0) {
        process = expression.Process.filter(function (obj) { return columnObj.rowText.indexOf(obj.Field) != -1 });
    }

    if (process.length > 0) {
        process = process[0];
    } else {
        process = expression.Process.filter(function (obj) { return obj.Field == "All" })[0];
    }

    if (columnObj.manual) {
        currentModel[columnObj.rowText] = expression[columnObj.rowText];
        return;
    }

    if (typeof process == "undefined") {
        var isEditFrom = fs.form.mode.toUpperCase() == "EDIT";
        if (isEditFrom)
            currentModel[columnObj.rowText] = ko.observable(fs.util.getNumberFromObjectAndFix(expression, columnObj.rowText, 0, expression.digits));

        if (columnObj.reference) {
            columnObj.expression(currentModel);
        }
        return;
    }


    if (process.Exp.skip || process.Exp.dataFromLastMonth) {
        simpleConnector(currentModel, columnObj, expression, process.Exp.dataFromLastMonth);
        return;
    }

    if (process.Exp.mode == "refrence") {
        var isLoadingFile = process.Exp.list.indexOf('LoadingFile') != -1;
        var _style = "green";
        if (process.Exp.manual || isLoadingFile)
            _style = "green_loading";

        if (isLoadingFile) {
            currentModel.style(expression.style ? expression.style : _style);
            currentModel[columnObj.rowText + "style"] = expression.style ? expression.style : _style;

            if (expression[columnObj.rowText] && expression[columnObj.rowText] != 0) {
                currentModel[columnObj.rowText] = ko.observable(expression[columnObj.rowText]);
                return;
            }
        } else {

            currentModel.style(expression.style ? expression.style : _style);
            currentModel[columnObj.rowText + "style"] = expression.style ? expression.style : _style;
        }
        window.fs_value = 0, temp = '';

        var fieldtype = columnObj.rowText;
        fieldtype = columnObj.month ? columnObj.month : fieldtype;
        if (process.Exp.postf) {
            fieldtype += ("_" + process.Exp.postf);
        }
        if (process.Exp.profix) {
            fieldtype = process.Exp.profix + "_" + fieldtype;
        }

        if (process.Exp.fields.length > 1)
            for (var i = 0; i < process.Exp.fields.length; i++) {

                var _equ = process.Exp.equ.length > 1 ? process.Exp.equ[i] : process.Exp.equ[0];

                fs.util.eval(String.format('fs_value {0}=({1})',
                _equ,
                refrenceData.get(process.Exp.list, fieldtype, process.Exp.fields[i], process.Exp, columnObj.index)));
            }
        else
            fs_value = refrenceData.get(process.Exp.list, fieldtype, process.Exp.fields[0], process.Exp, columnObj.index);


        if (process.Exp.addition) {
            fs_value = fs.util.eval(String.format(process.Exp.addition, fs_value));
        }

        if (isLoadingFile) {
            fs_value = (process.Exp.toFix == false ? fs_value : fs_value / 1000).toFix();
            currentModel[columnObj.rowText] = ko.observable(fs_value);
        }
        else {
            currentModel[columnObj.rowText] = fs_value.toFix();
        }
    }
    else {
        currentModel.style(expression.style ? expression.style : "blue");
        currentModel[columnObj.rowText + "style"] = expression.style ? expression.style : "blue";

        var _index = expression.index;
        if (process.Exp.index) {
            _index = process.Exp.index;
        }
        if (typeof _index == "undefined")
            _index = 0;

        searchData.put({ description: expression.description, accountcode: expression.accountcode }, columnObj.rowText, process.Exp, _index);
    }
}


fs = (function (inner) {
    inner.page = inner.page || {};

    inner.page.cache = [];
    inner.page.loader = function (option) {

    }

    return inner;
} (fs || {}))


